	<?php $this->load->view('common/head')?>
	
	<!-- Begin of Sidebar -->
	<?php $this->load->view('common/sidebar')?>
	
<link rel="stylesheet" href="<?php echo $this->config->item('css')?>/rating.css">	
<script src="<?php echo $this->config->item('js')?>/jquery.rating.js"></script>	
	
	<?php /*********************************/ ?>
	
	<!-- Modal Box Content -->
	<div id="dialog" title="About" style="display: none;">
		<p class='p1'></p>
		<p class='p2'></p>
	</div> 
	<!--! end of #info-dialog -->
			
	<div id="dialog-confirm" title="Delete?" style="display: none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This Person will be permanently deleted and cannot be recovered. Are you sure?</p>
	</div>
	
		
    <!-- Begin of #main -->
    <div id="main" role="main">
    	
    	<!-- Begin of titlebar/breadcrumbs -->
		<div id="title-bar">
			<ul id="breadcrumbs">
				<li><a href="<?php echo site_url()?>" title="Home"><span id="bc-home"></span></a></li>
				<li><a href="contact" title="Contacts">Contacts</a></li>
				<li class="no-hover">Main</li>
			</ul>
		</div> <!--! end of #title-bar -->
		
		<div class="shadow-bottom shadow-titlebar"></div>
		
		<!-- Begin of #main-content -->
		<div id="main-content">
			<div class="container_12">
			
			<!-- Put your content here! -->
			<div class="grid_12">
				<div class="block-border">
				<div class="block-header"><h1>Contacts</h1></div>
				<div class="block-content">
						<div class="block-actions">
							<ul class="actions-right">
								<li><button class="submit" onClick="load_form()">Add New Contact</button></li>
								<li><button class="submit">Filter Contact</button></li>
							</ul>
						</div>
					</div>
					</div>
			</div>

			
			
			<!--  -->
		<div class="grid_6">
			<div class="block-border">
				<div class="block-header">
					<h1 id="for_title">Options & Settings for (Contacts)</h1><span></span>
				</div>
				<div class="block-content ">
					<div class="load_option"></div>
				</div>

			</div>
		</div>
			
			
			<!--  -->
			<div class="grid_6">
				<div class="block-border">
					<div class="block-header">
						<h1 id="az_h1"><center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center></h1><span></span>
					</div>
					
					<div class="block-content a-z-list">
						<div id="slider_2">
						</div>
					</div>
				</div>
			</div>
			
			<div class="clear height-fix"></div>

		</div></div> <!--! end of #main-content -->
  </div> <!--! end of #main -->	



	<?php /****************************/ ?>
	<script type="text/javascript">
		
		/** history **/
		function history(com)
		{
			
			$('p.p1').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');
			$('p.p2').html(com).hide();
			$("#dialog").dialog({title:"Loading History... ", autoOpen:true});
			$.post("<?php echo site_url('history/view_contact_history/')?>/"+com,
				
				function(data){
					temp='';
					$.each(data,function(index,value) {

						temp+='<div class="block-header"><p style="padding-left:25px;"><b>'+value['first_name']+' '+value['last_name']+'</b> <sup>'+value['date']+'</sup></p></div><div class="block-content">';
						temp+='<p>'+value['note']+'</p></div>';
						temp+='';
					})
					temp+='<div class="clear height-fix"></div>';
				$('p.p1').html(temp);				
			},'json');
			
			$('p.p2').load('<?php echo site_url('history/form_contact/')?>/'+com, function() {
				  $('p.p1, p.p2').fadeIn('slow');
				  $("#dialog").dialog({title:"Contact History"});
			});
		}
		/** END history **/
		
				
		/** load_form **/
		function load_form(id)
		{
			$('.load_option').slideUp('slow');
			$('#for_title').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');
			if(id==null)
			{
				//load empty form
				$('.load_option').load('contact/form', function() {
				  $('#for_title').html('Add New Contact');
				  $('.load_option').slideDown('slow');
				});
			}
			else{
				//load form
				$('.load_option').load('contact/form/'+id, function() {
				  $('#for_title').html('Edit Contact');
				  $('.load_option').slideDown('slow');
				});
			}
		}
		/** END load_form **/
		
				
		/** function Delete **/
		function del(com)
		{
			//$( "#dialog-confirm" ).dialog(open);
			$( "#dialog-confirm" ).dialog({
				resizable: false,
				height:150,
				modal: true,
				buttons: {
					"Are You Sure ? (Yes Delete!)": function() {
							$('#for_title').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');
							$.post("<?php echo site_url('contact/delete/')?>/"+com,
								function(data){
									//alert(data)
									if(!data.error){
										$.jGrowl( data.msg, { theme: 'saved',position:'center'  });
										$('.a-z-list').parent().children('.block-content').slideToggle();
										a_z_list();
										$('#for_title').html('Options & Settings for (Contacts)');
										$('.load_option').slideUp('slow');
									}
									else{
										$.jGrowl('Error: '+data.msg, { theme: 'error',position:'center'  });
									}
							},'json');
							$( this ).dialog( "close" );
					},
					Cancel: function() {
						$( this ).dialog( "close" );
					}
				}
			});
			
		}
		/** End function Delete **/
						
		/** A-Z List**/
		function a_z_list()
		{
			$('#az_h1').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');
			$('#slider_2').html('');
			yi = 0;
			slider_2 = "";
			ar_array2 = new Array();
			//group by 
			$.post("<?php echo site_url('contact/get_contact_info/')?>/",
				function(data){
				slider_2+= '<div class="slider-content"><ul>';
					$.each(data,function(xix,ee) {
					yi++;
					//xix = the character //yy = the objects
					//put character this array to pass the items option
					ar_array2[yi] = xix;
					//character title (above the names)
					slider_2+='<li id="'+xix+'"><a name="'+xix+'" class="title">'+xix+'</a><ul>';
						
						for(var i=0; i < ee.length; i++){
							slider_2+='<li><a href="javascript:void('+ee[i].id+');" onClick="load_info('+ee[i].id+')">'+ee[i].name+'</a></li>';
						}//end for
					slider_2+='	</ul></li>';
					})//end .each
					slider_2+='</div>';
					$('#slider_2').append(slider_2).sliderNav({items:ar_array2});
					$('#az_h1').html('A-Z List');
			}, 'json');
		$('.a-z-list').parent().children('.block-content').slideToggle();
		}
		/** END A-Z List **/
		
					
		/*** function load info **/
		function load_info(com)
		{

			//Reset all 
			$('.load_option').slideUp('slow');
			$('#for_title').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');

			info = '';
								
			$.post("<?php echo site_url('contact/get_contact_info/')?>/"+com,
				function(data){					
					QR = Array();
					QR['name']	 = data.name_ar;
					QR['email']	 = data.email;
					QR['mobile1']= data.mobile1;
					if(data.job_des)  QR['job_des'] = data.job_des;  else QR['job_des']= '';
					if(data.com_name) QR['com_name']= data.com_name; else QR['com_name']= '';
					
					info+='<div class="alert note"><strong>Actions</strong> for : '+data.name_ar+' </div>';
					info+='<div class="block-content">'
					info+='<ul class="block-list with-icon">'
					info+='<li class="i-16-calendar"><a href="javascript:;" onClick="load_form('+com+')">Edit</a></li>'
					info+='<li class="i-16-cross"><a href="javascript:;" onClick="del('+com+')">Delete</a></li>'
					info+='<li class="i-16-flag"><a href="javascript:;" onClick="flag('+com+')">Add New Flag</a></li>'
					info+='<li class="i-16-jar"><a href="javascript:;" onClick="history('+com+')">History Record for this Contact</a></li>'
					info+='</ul>'
					info+='</div>'
					
					info+='<div class="block-content">'
					info+='<p class="rate_info"></p>'
					info+='<ul class="block-list with-icon">'
					info+='<li class=""><a href="javascript:;">Rate this Contact</a>'
					info+='<div id="rate1" class="rating">&nbsp;</div><div class="implementation"></div>'
					info+='</li>'
					
					info+='</ul>'
					info+='</div>'
					
					
					info+='<div class="alert success"><strong>About</strong> '+data.name_ar+' </div>';
					info+='<div class="block-content">';
					info+='<ul class="block-list with-icon">'
					info+='<li class="i-16-briefcase"> '+data.name_ar+'</li>';
					info+='<li class="i-16-mail">'+data.email+'</li>';
					info+='<li class="i-16-telephone">'+data.mobile1+'</li>';
					if(data.com_name)
						info+='<li class="i-16-processor">'+data.job_des+'</li>';
					else
						info+='<li class="i-16-rocket-fly"><span style="color:red">NO Job Des. set</span></li>';
					if(data.com_name) 
						info+='<li class="i-16-rocket-fly">'+data.com_name+'</li>';
					else
						info+='<li class="i-16-rocket-fly"><span style="color:red">NO Company set</span></li>';
					if(data.country)
						info+='<li class="i-16-map"><img src="<?php echo $this->config->item('images')?>/flags/'+data.country+'.gif" alt="'+data.country+'" title="'+data.country+'" /> '+data.country+'</li>';
					else
						info+='<li class="i-16-map"><img src="<?php echo $this->config->item('images')?>/flags/space.gif" /> <span style="color:red">Please Set The Country </span> </li>';
					if(data.country)
						info+='<li class="i-16-map">'+data.city+'</li>';
					else
					info+='<li class="i-16-map"><img src="<?php echo $this->config->item('images')?>/flags/space.gif" /> <span style="color:red">Please Set The City </span> </li>';

					info+='<li><table cellpadding=5 cellspacing=5><tr><td><a href="javascript:;" onClick="toggle(25)">QR (250x250)</a></td><td><a href="javascript:;" onClick="toggle(15)">QR (150x150)</a></td></tr> ';
					info+='<tr><td><img id="img25" style="display:none" src="http://chart.apis.google.com/chart?cht=qr&chs=250x250&chld=L&choe=UTF-8&chl=MECARD:N:'+QR['name']+';EMAIL:'+QR['email']+';NOTE:'+QR['job_des']+';ORG:'+QR['com_name']+';TEL:'+QR['mobile1']+';"/></td>';
					info+='<td><img id="img15" style="display:none" src="http://chart.apis.google.com/chart?cht=qr&chs=150x150&chld=L&choe=UTF-8&chl=MECARD:N:'+QR['name']+';EMAIL:'+QR['email']+';NOTE:'+QR['job_des']+';ORG:'+QR['com_name']+';TEL:'+QR['mobile1']+';"/></li></td></tr></table> ';
					info+='</ul>';
					info+='</div>';
					
					info+='<div><br></div>';
					
					$('.load_option').html(info);
					$('.load_option').slideDown('slow');
					$('#for_title').html(data.name_ar);
					$('#rate1').rating('<?php echo site_url('rate/contact/')?>/'+com+'/', {maxvalue:5,increment:.5});
					
					$('.rate_info').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');
					/***** Rate *****/
					$.post("<?php echo site_url('contact/get_contact_rate/')?>/"+com,
						function(data3){
							rate = '';
							if(data3.rate.rate){
								rate+='<div class="alert info">Current Rate for <u>'+data.name_ar+'</u> is: <b>'+Math.round(data3.rate.rate*1000)/1000+'/5</b><sup><i>'+data3.rate_count+' vote(s)</i></sup> </div>';
							}
							else{
								rate+='<div class="alert warning no-margin"><strong>Information</strong> No Rates For  '+data.name_ar+' Found!</div>';
							}
						$('.rate_info').html(rate).fadeIn();	
					},'json');
					/**** End Rate ***/
			}, 'json');
		}
		
		/*** END load info **/	
					
		/*** add flags form ***/
		function flag(com)
		{
			$('p.p1, p.p2').html(com).hide();
			$("#dialog").dialog({title:"Loading Form...", autoOpen:true});
			$('p.p1').load('<?php echo site_url('flag/contact/')?>/'+com, function() {
				  $('p.p1').fadeIn('slow');
				  $("#dialog").dialog({title:"Add Flags to Contact"});
			});
		}
		/*** End add flags form ***/
		
		function toggle(n){
			$('#img25,#img15').slideUp();	
			$('#img'+n).fadeIn();
		}
		

		
	$().ready(function() {
	
	$('#dialog').dialog({ 
			minWidth: 550,
			position: "top",
			autoOpen: false,
			modal: true, 
			show: "slide", 
			hide: "slide",
			title: "Loading Company Info..." 
	});
		$('.a-z-list').parent().children('.block-content').slideToggle();
		a_z_list();
		
		});
		
		
    </script>
    
	<?php /****************************/ ?>




	
	
	
	<?php /*********************************/ ?>
	<!-- Begin of footer -->
	<?php $this->load->view('common/footer')?>
